      SUBROUTINE SMRIN1()  
C  
C CHANGE RECORD  
C  
      USE GLOBAL  

      PARAMETER (SMCW2=2.739726E-5)   ! *** cm/y to m/day
      CHARACTER TITLE(3)*79, CCMRM*1  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMKPOC  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMKPON  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMKPOP  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMTHKC  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMTHKN  
      REAL,SAVE,ALLOCATABLE,DIMENSION(:)::SMTHKP  

      IF(.NOT.ALLOCATED(SMKPOC))THEN
		ALLOCATE(SMKPOC(NSMGM))
		ALLOCATE(SMKPON(NSMGM))
		ALLOCATE(SMKPOP(NSMGM))
		ALLOCATE(SMTHKC(NSMGM))
		ALLOCATE(SMTHKN(NSMGM))
		ALLOCATE(SMTHKP(NSMGM))
	    SMKPOC=0.0 
	    SMKPON=0.0 
	    SMKPOP=0.0 
	    SMTHKC=0.0 
	    SMTHKN=0.0 
	    SMTHKP=0.0 
	ENDIF
C  
      OPEN(2,FILE='WQ3D'//ans(partid2)//'.OUT',STATUS='UNKNOWN',POSITION='APPEND')  
      OPEN(1,FILE='WQ3DSD.INP',STATUS='UNKNOWN')  
      PRINT *,'WQ: SD READING WQ3DSD.INP - MAIN DIAGENESIS CONTROL FILE'
C  
C READ FIRST LINE IN WQ3DSD.INP FILE.  IF FIRST CHARACTER IS '#', THEN  
C THIS IS THE NEW VERSION WITH ANNOTATED COMMENTS ADDED (I.E., USES THE  
C SKIPCOMM SUBROUTINE TO SKIP COMMENT LINES.  COMMENT LINES BEGIN WITH  
C A "C", "C", OR "#" CHARACTER IN COLUMN 1.  IF "#" IS NOT FOUND AS THE  
C FIRST CHARACTER IN THE FILE, THEN THE OLD METHOD OF READING THE  
C WQ3DSD.INP FILE IS USED TO PRESERVE BACKWARD COMPATABILITY.  
C  
      ISSKIP = 0  
      READ(1,'(A1)') CCMRM  
      BACKSPACE(1)  
      IF(CCMRM .EQ. '#') ISSKIP = 1  
      CCMRM = '#'  
C  
C01 READ MAIN TITLE CARDS:  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) (TITLE(M), M=1,3)  
      WRITE(2,999)  
      WRITE(2,5100) (TITLE(M), M=1,3)  
C  
C02 I/O CONTROL VARIABLES AND TEMPERATURE RELATED VARIABLES  
C  
      WRITE(2,999)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) ISMZ,ISMICI,ISMRST,ISMHYST,ISMZB  
      WRITE(2,53)'* # OF ZONES FOR SPAT. VARY. PARAMETERS IN SPM =',ISMZ
C *** PMC BEGIN BLOCK  
C      IF(ISMZ.GT.NSMZ) STOP 'ERROR!! ISMZ SHOULD BE <= NSMZ'   PMC  
      NSMZ=ISMZ  
C *** PMC END BLOCK  
      IF(ISMICI.EQ.1)THEN  
      WRITE(2,50)'* SPATIALLY/TEMPORALLY-VARYING ICS FROM WQSDICI.INP'  
      ELSE IF(ISMICI.EQ.2)THEN  
      WRITE(2,50)'* SPATIALLY/TEMPORALLY-VARYING ICS FROM WQSDRST.INP'  
      ELSE  
      WRITE(2,50)'* SPATIALLY/TEMPORALLY CONSTANT INITIAL CONDITIONS'  
      ENDIF  
      IF(ISMRST.EQ.1)THEN  
      WRITE(2,50)'* WRITE SPATIAL DISTRIBUTIONS TO WQSDRST.OUT'  
      ELSE  
      WRITE(2,50)'* NO WRITING TO ISMORST                           '  
      ENDIF  
      IF(ISMHYST.EQ.1)THEN  
      WRITE(2,50)'* HYSTERESIS IN BENTHIC MIXING IS ACTIVATED       '  
      ELSE  
      WRITE(2,50)'* HYSTERESIS IN BENTHIC MIXING IS NOT ACTIVATED   '  
      ENDIF  
      IF(ISMZB.EQ.1)THEN  
      WRITE(2,50)'* DIAGNOSTIC OUTPUT FOR FUNC ZBRENT (ZBRENT.LOG)  '  
        OPEN(99,FILE='ZBRENT.LOG',STATUS='UNKNOWN')  
        CLOSE(99,STATUS='DELETE')  
        OPEN(99,FILE='ZBRENT.LOG',STATUS='UNKNOWN')  
      WRITE(99,53)'   ITNWQ    L    I    J         SOD          '  
        CLOSE(99)  
      ELSE  
      WRITE(2,50)'* NO DIAGNOSTIC OUTPUT FOR FUNC ZBRENT            '  
      ENDIF  
C  
C03  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) ISMTS,TSMTSB,TSMTSE,SMTSDT, ISSDBIN  
      IF(ISMTS.GT.NWQTS)THEN  
      WRITE(2,50)'** ISMTS SHOULD BE <= NWQTS **                    '  
        ISMTS=NWQTS  
      ENDIF  
      WRITE(2,84)  
     &    '* TIME-SERIES OUTPUT FROM ', TSMTSB, ' DAY ',  
     &    '                       TO ', TSMTSE, ' DAY ',  
     &    '                    EVERY ', SMTSDT, ' HOUR',  
     &    '                       AT ', ISMTS,  ' LOCATIONS',  
     &    ' BIN FILE SWITCH ISSDBIN =', ISSDBIN,' (0=OFF)'  
      IF(ISMTS.GT.0)THEN
        OPEN(1,FILE='WQSDTS1.OUT',STATUS='UNKNOWN')  
        CLOSE(1,STATUS='DELETE')  
        OPEN(1,FILE='WQSDTS2.OUT',STATUS='UNKNOWN')  
        CLOSE(1,STATUS='DELETE')  
        OPEN(1,FILE='WQSDTS1.OUT',STATUS='UNKNOWN')  
        WRITE(1,1996)  
        CLOSE(1)  
        OPEN(1,FILE='WQSDTS2.OUT',STATUS='UNKNOWN')  
        WRITE(1,1997)  
        CLOSE(1)  

 1996   FORMAT('C   I    J      TIME       NH41      NH42',  
     &      '        FNH4       NO31       NO32      FNO3',  
     &      '        PO41       PO42      FPO4D      H2S1',  
     &      '        H2S2      BFO2       BFCOD       SI1',  
     &      '        SI2       FSAD        SMT        BST',  
     &      '        PON        POP        POC')  
 1997   FORMAT('C   I    J      TIME       CSOD      NSOD',  
     &      '       D1PO4       D1SI        SS       JNIT',  
     &      '       JDEN      JAQH2S     JGCH4       DGFN',  
     &      '       DGFP       DGFC       DFN1       DFN2',  
     &      '       DFN3       DFP1       DFP2       DFP3',  
     &      '       DFC1       DFC2       DFC3')  
      ENDIF
C  
C ISSDBIN > 0 TURNS ON BINARY FILE OUTPUT FOR BENTHIC FLUX RATES  
C  
      IF(ISSDBIN .GT. 0)THEN  
        CALL WQZERO4  
        CALL INITBIN4  
      ENDIF  
C  
C04  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,50) TITLE(1)  
      WRITE(2,999)  
      IF(ISMTS.GE.1)THEN  
        WRITE(2,50)': ICSMTS(I)=1, TIME-SERIES OUTPUT FOR VARIABLE I'  
        WRITE(2,50)': ICSMTS(I)\=1, NO TIME-SERIES OUTPUT FOR VAR. I'  
        WRITE(2,999)  
        WRITE(2,50) TITLE(1)  
C  
C04  
C  
        DO M=1,ISMTS  
          READ(1,5101) II,JJ,(ICSMTS(NW,M),NW=1,NTSSMV)  
          IF(IJCT(II,JJ).LT.1 .OR. IJCT(II,JJ).GT.8)THEN  
            PRINT*, 'I, J = ', II,JJ  
            STOP 'ERROR!! INVALID (I,J): TIME-SERIES LOCATION'  
          ENDIF  
          LSMTS(M)=LIJ(II,JJ)  
          WRITE(2,5101) II,JJ,(ICSMTS(NW,M),NW=1,NTSSMV)  
        ENDDO  
      ENDIF  
      ISMTSB = NINT(TSMTSB/DTD)  
      ISMTSE = NINT(TSMTSE/DTD)  
      ISMTSDT = NINT(SMTSDT*3600.0/DT)  
      WRITE(2,53)': TIME-SERIES STARTING TIME STEP (IN DT UNIT) = ',  
     &    ISMTSB  
      WRITE(2,53)': TIME-SERIES ENDING TIME STEP (IN DT UNIT)   = ',  
     &    ISMTSE  
      WRITE(2,53)': FREQUENCY OF TS OUTPUT  (IN DT UNIT)        = ',  
     &    ISMTSDT  
C PMC      IF(MOD(ISMTSDT,IWQDT).NE.0)  
C PMC     &    STOP 'ERROR!! ISMTSDT SHOULD BE MULTIPLE OF IWQDT'  
  999 FORMAT(1X)  
 5100 FORMAT(A79)  
 5101 FORMAT(10I8)  
 5103 FORMAT(10F8.4)  
 5104 FORMAT(I8, 3F8.4)  
   50 FORMAT(A50)  
   51 FORMAT(A27, 3(F8.4,2X))  
   52 FORMAT((A45, E11.4))  
   53 FORMAT((A48, I10))  
   55 FORMAT(A31, 2I5)  
   84 FORMAT(3(A26,F10.4,A5,/), 2(A26,I8,A10,/))  
C  
C05  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      WRITE(2,999)  
      READ(1,5103) SMDIFT  
      WRITE(2,52)'* DIFF COEFF (M^2/S) FOR SED TEMPERATURE   = ',SMDIFT  
      SMDIFT = SMDIFT*8.64E4   ! *** Convert to m^2/day
C  
C06 SPATIALLY CONSTANT PARAMETERS FOR SPLITING DEPOSITIONAL FLUXES OF AL  
C  
      WRITE(2,999)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
C  
C07  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      WRITE(2,999)  
      READ(1,*) SMFNBC(1),SMFNBC(2),SMFNBC(3),SMFNBD(1),SMFNBD(2),  
     &    SMFNBD(3),SMFNBG(1),SMFNBG(2),SMFNBG(3)  
      WRITE(2,50)'* CYANOBACTERIA-N SPLIT INTO G1, G2 & G3 CLASSES  '  
      WRITE(2,51)' : (FNBC1, FNBC2, FNBC3) = ', (SMFNBC(M),M=1,3)  
      WRITE(2,50)'* DIATOMS-N SPLIT INTO G1, G2 & G3 CLASSES        '  
      WRITE(2,51)' : (FNBD1, FNBD2, FNBD3) = ', (SMFNBD(M),M=1,3)  
      WRITE(2,50)'* BLUE-GREEN ALGAE-N SPLIT INTO G1, G2, G3 CLASSES'  
      WRITE(2,51)' : (FNBG1, FNBG2, FNBG3) = ', (SMFNBG(M),M=1,3)  
      SUMNBC=SMFNBC(1)+SMFNBC(2)+SMFNBC(3)  
      SUMNBD=SMFNBD(1)+SMFNBD(2)+SMFNBD(3)  
      SUMNBG=SMFNBG(1)+SMFNBG(2)+SMFNBG(3)  
      IF(SUMNBC.LT.0.9999.OR.SUMNBC.GT.1.0001)  
     &    STOP 'ERROR!! SMFNBC(1)+SMFNBC(2)+SMFNBC(3) SHOULD BE 1'  
      IF(SUMNBD.LT.0.9999.OR.SUMNBD.GT.1.0001)  
     &    STOP 'ERROR!! SMFNBD(1)+SMFNBD(2)+SMFNBD(3) SHOULD BE 1'  
      IF(SUMNBG.LT.0.9999.OR.SUMNBG.GT.1.0001)  
     &    STOP 'ERROR!! SMFNBG(1)+SMFNBG(2)+SMFNBG(3) SHOULD BE 1'  
C  
C07  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      WRITE(2,999)  
      READ(1,*) SMFPBC(1),SMFPBC(2),SMFPBC(3),SMFPBD(1),SMFPBD(2),  
     &    SMFPBD(3),SMFPBG(1),SMFPBG(2),SMFPBG(3)  
      WRITE(2,50)'* CYANOBACTERIA-P SPLIT INTO G1, G2 & G3 CLASSES  '  
      WRITE(2,51)' : (FPBC1, FPBC2, FPBC3) = ', (SMFPBC(M),M=1,3)  
      WRITE(2,50)'* DIATOMS-P SPLIT INTO G1, G2 & G3 CLASSES        '  
      WRITE(2,51)' : (FPBD1, FPBD2, FPBD3) = ', (SMFPBD(M),M=1,3)  
      WRITE(2,50)'* BLUE-GREEN ALGAE-P SPLIT INTO G1, G2, G3 CLASSES'  
      WRITE(2,51)' : (FPBG1, FPBG2, FPBG3) = ', (SMFPBG(M),M=1,3)  
      SUMPBC=SMFPBC(1)+SMFPBC(2)+SMFPBC(3)  
      SUMPBD=SMFPBD(1)+SMFPBD(2)+SMFPBD(3)  
      SUMPBG=SMFPBG(1)+SMFPBG(2)+SMFPBG(3)  
      IF(SUMPBC.LT.0.9999.OR.SUMPBC.GT.1.0001)  
     &    STOP 'ERROR!! SMFPBC(1)+SMFPBC(2)+SMFPBC(3) SHOULD BE 1'  
      IF(SUMPBD.LT.0.9999.OR.SUMPBD.GT.1.0001)  
     &    STOP 'ERROR!! SMFPBD(1)+SMFPBD(2)+SMFPBD(3) SHOULD BE 1'  
      IF(SUMPBG.LT.0.9999.OR.SUMNBG.GT.1.0001)  
     &    STOP 'ERROR!! SMFPBG(1)+SMFPBG(2)+SMFPBG(3) SHOULD BE 1'  
C  
C08  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      WRITE(2,999)  
      READ(1,*) SMFCBC(1),SMFCBC(2),SMFCBC(3),SMFCBD(1),SMFCBD(2),  
     &    SMFCBD(3),SMFCBG(1),SMFCBG(2),SMFCBG(3)  
      WRITE(2,50)'* CYANOBACTERIA-C SPLIT INTO G1, G2 & G3 CLASSES  '  
      WRITE(2,51)' : (FCBC1, FCBC2, FCBC3) = ', (SMFCBC(M),M=1,3)  
      WRITE(2,50)'* DIATOMS-C SPLIT INTO G1, G2 & G3 CLASSES        '  
      WRITE(2,51)' : (FCBD1, FCBD2, FCBD3) = ', (SMFCBD(M),M=1,3)  
      WRITE(2,50)'* BLUE-GREEN ALGAE-C SPLIT INTO G1, G2, G3 CLASSES'  
      WRITE(2,51)' : (FCBG1, FCBG2, FCBG3) = ', (SMFCBG(M),M=1,3)  
      SUMCBC=SMFCBC(1)+SMFCBC(2)+SMFCBC(3)  
      SUMCBD=SMFCBD(1)+SMFCBD(2)+SMFCBD(3)  
      SUMCBG=SMFCBG(1)+SMFCBG(2)+SMFCBG(3)  
      IF(SUMCBC.LT.0.9999.OR.SUMCBC.GT.1.0001)  
     &    STOP 'ERROR!! SMFCBC(1)+SMFCBC(2)+SMFCBC(3) SHOULD BE 1'  
      IF(SUMCBD.LT.0.9999.OR.SUMCBD.GT.1.0001)  
     &    STOP 'ERROR!! SMFPBD(1)+SMFCBD(2)+SMFCBD(3) SHOULD BE 1'  
      IF(SUMCBG.LT.0.9999.OR.SUMCBG.GT.1.0001)  
     &    STOP 'ERROR!! SMFCBG(1)+SMFCBG(2)+SMFCBG(3) SHOULD BE 1'  
C  
C09 SPATIALLY CONSTANT PARAMETERS FOR DIAGENESIS  
C  
      WRITE(2,999)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMKPON(1),SMKPON(2),SMKPON(3),SMKPOP(1),SMKPOP(2),  
     &    SMKPOP(3),SMKPOC(1),SMKPOC(2),SMKPOC(3)  
      WRITE(2,50)'* DIAGENESIS RATE AT 20OC IN LAYER 2 (/DAY)       '  
      WRITE(2,51)' : (KPON1,KPON2,KPON3)   = ', (SMKPON(M),M=1,3)  
      WRITE(2,51)' : (KPOP1,KPOP2,KPOP3)   = ', (SMKPOP(M),M=1,3)  
      WRITE(2,51)' : (KPOC1,KPOC2,KPOC3)   = ', (SMKPOC(M),M=1,3)  
C  
C10  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMTHKN(1),SMTHKN(2),SMTHKN(3),SMTHKP(1),SMTHKP(2),  
     &    SMTHKP(3),SMTHKC(1),SMTHKC(2),SMTHKC(3)  
      WRITE(2,50)'* TEMPERATURE EFFECT ON DIAGENESIS RATE           '  
      WRITE(2,51)' : (THKN1,THKN2,THKN3)   = ', (SMTHKN(M),M=1,3)  
      WRITE(2,51)' : (THKP1,THKP2,THKP3)   = ', (SMTHKP(M),M=1,3)  
      WRITE(2,51)' : (THKC1,THKC2,THKC3)   = ', (SMTHKC(M),M=1,3)  
      WRITE(2,999)  
C  
C11  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMM1,SMM2,SMTHDD,SMTHDP,SMPOCR,SMKMDP,SMKBST,  
     &    XSMDPMIN,SMRBIBT  
C  
C12  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMO2BS,SMTDMBS,SMTCMBS  
      WRITE(2,50)'* SOLID CONCENTRATIONS (KG/L) IN LAYERS 1 AND 2   '  
      WRITE(2,51)' : (RM1, RM2)            = ', SMM1,SMM2  
      WRITE(2,50)'* TEMP EFFECT ON MIXING IN DISSOLVED & PARTICULATE'  
      WRITE(2,51)' : (THDD, THDP)          = ', SMTHDD,SMTHDP  
      WRITE(2,52)'* HALF-SAT. CONST OF O2 FOR PARTICLE MIXING= ',SMKMDP  
     &    ,': FIRST-ORDER DECAY RATE FOR STRESS (/DAY) = ',SMKBST  
     &    ,'* RATIO OF BIO-IRRIGATION TO BIOTURBATION  = ',SMRBIBT  
     &    ,'* REFERENCE CONC (GC/M^3) FOR GPOC(1)      = ',SMPOCR  
     &    ,'* MINIMUM DIFFUSION COEFF (M^2/DAY)        = ',XSMDPMIN  
     &    ,'* CRITICAL O2 (G/M^3) FOR BENTH. HYSTERESIS= ',SMO2BS  
     &    ,': TIME LAG (DAYS) FOR MAX STRESS TO BE KEPT= ',SMTDMBS  
     &    ,': TIME DURATION (D) ABOVE WHICH HYSTERESIS = ',SMTCMBS  
      ISMTDMBS = NINT(SMTDMBS/DTWQ)  
      ISMTCMBS = NINT(SMTCMBS/DTWQ)  
      SM1OKMDP = 1.0/SMKMDP  
      SMBST1 = 1.0 / (1.0 + SMKBST*DTWQ)  
      WRITE(2,999)  
C  
C13  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMP1NH4,SMP2NH4,SMKMNH4,SMKMO2N,SMTHNH4,SMTHNO3,  
     &    SMP2PO4,SMCO2PO4  
      WRITE(2,50)'* PARTITION COEFF BET/ DISSOLVED AND SORBED NH4   '  
      WRITE(2,51)' : (P1NH4, P2NH4)        = ', SMP1NH4,SMP2NH4  
      WRITE(2,50)'* HALF-SAT. CONST FOR NITRI. (GN/M^3, GO2/M^3)    '  
      WRITE(2,51)' : (KMNH4, KMNH4O2)      = ', SMKMNH4,SMKMO2N  
      WRITE(2,50)'* TEMP EFFECT ON KNH4 & KNO3                      '  
      WRITE(2,51)' : (THNH4, THNO3)        = ', SMTHNH4,SMTHNO3  
      WRITE(2,52)'* ANAEROBIC (LAY1) PARTITION COEF FOR PO4 (L/KG) = '
     &                                                    ,SMP2PO4  
     &    ,': CRITICAL DO (MG/L) FOR PO4 SORPTION      = ',SMCO2PO4  
      SMFD1NH4 = 1.0 / (1.0 + SMM1*SMP1NH4)  
      SMFP1NH4 = 1.0 - SMFD1NH4  
      SMFD2NH4 = 1.0 / (1.0 + SMM2*SMP2NH4)  
      SMFP2NH4 = 1.0 - SMFD2NH4  
      SMKMO2N = SMKMO2N * 2.0  
      SMFD2PO4 = 1.0 / (1.0 + SMM2*SMP2PO4)  
      SMFP2PO4 = 1.0 - SMFD2PO4  
      WRITE(2,999)  
C  
C14  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMP1H2S,SMP2H2S,SMKD1HS,SMKP1HS,SMTHH2S,SMKMH2S,  
     &    SMKCH4,SMTHCH4,SMCSHSCH  
      WRITE(2,50)'* PARTITION COEFF FOR H2S IN LAYER 1 (L/KG)       '  
      WRITE(2,51)' : (P1H2S, P2H2S)        = ', SMP1H2S,SMP2H2S  
      WRITE(2,50)'* REACTION VEL (M/D) FOR DISSOL & PART. IN LAYER 1'  
      WRITE(2,51)' : (KH2SD1, KH2SP1)      = ', SMKD1HS,SMKP1HS  
      WRITE(2,52)'* CRITICAL SAL (PPT) FOR H2S/CH4 OXIDATION = ',  
     &    SMCSHSCH  
      WRITE(2,52)'* TEMPERATURE EFFECT ON H2S OXIDATION RATE = ',SMTHH2S  
     &    ,': OXYGEN EFFECT (MG/L) ON H2S OXIDATION    = ',SMKMH2S  
      WRITE(2,52)'* METHANE OXIDATION REACTION VELOCITY (M/D)= ',SMKCH4  
     &    ,': TEMPERATURE EFFECT ON CH4 OXIDATION RATE = ',SMTHCH4  
      SMFD1H2S = 1.0 / (1.0 + SMM1*SMP1H2S)  
      SMFP1H2S = 1.0 - SMFD1H2S  
      SMFD2H2S = 1.0 / (1.0 + SMM2*SMP2H2S)  
      SMFP2H2S = 1.0 - SMFD2H2S  
      XSMK1H2S = (SMKD1HS*SMKD1HS*SMFD1H2S + SMKP1HS*SMKP1HS*SMFP1H2S)  
     &    / (2.0*SMKMH2S)  
C  
C15  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMO2C,SMO2NO3,SMO2NH4  
      WRITE(2,52)'* STOICHI COEF FOR C USED BY H2S OX (GO2/GC)=',SMO2C  
     &    ,': STOICHI COEF FOR C USED BY DENITR (GO2/GN)=',SMO2NO3  
     &    ,': STOICHI COEF FOR O2 USED BY NITRI (GO2/GN)=',SMO2NH4  
      WRITE(2,999)  
C  
C16  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      IF(ISSKIP .EQ. 0) READ(1,999)  
      READ(1,*) SMKSI,SMTHSI,SMKMPSI,SMSISAT,SMP2SI,SMDP1SI,SMCO2SI,  
     &    SMJDSI  
      WRITE(2,52)'* PSI DISSOL. RATE AT 20C IN LAYER 2 (/D)  = ',SMKSI  
     &    ,': TEMPERATURE EFFECT ON PSI DISSOLUTION    = ',SMTHSI  
     &    ,': SAT. CONC. IN PORE WATER (G SI/M^3)      = ',SMSISAT  
     &    ,'* PARTITION COEF FOR SI IN LAYER 2 (L/KG)  = ',SMP2SI  
     &    ,': INCREMENTAL IN PART. COEF IN LAYER1, P1SI= ',SMDP1SI  
     &    ,': CRITICAL DO (MG/L) FOR SI SORPTION       = ',SMCO2SI  
     &    ,'* DETRITAL FLUX (G/M^2/D) EXCEPT DIATOMS   = ',SMJDSI  
     &    ,'* DISSOLUTION HALF-SAT CONSTANT (G SI/M^3) = ',SMKMPSI  
      SMFD2SI = 1.0 / (1.0 + SMM2*SMP2SI)  
      SMFP2SI = 1.0 - SMFD2SI  
C  
C SET UP LOOK-UP TABLE FOR TEMPERATURE DEPENDENCY OVER -5OC TO 35OC  
C  
      ! *** DSLLC BEGIN BLOCK
      WQTDsMIN=-10
      WQTDsMAX=+50
      STEMP=WQTDsMIN
      WQTDsINC=(WQTDsMAX-WQTDsMIN)/NWQTD
      DO IT=1,NWQTD  
        !STEMP = REAL(IT-1)*0.1 - 4.95  
        TT20 = STEMP-20.0  
        DO M=1,3  
          SMTDND(IT,M) = SMKPON(M) * SMTHKN(M)**TT20  
          SMTDPD(IT,M) = SMKPOP(M) * SMTHKP(M)**TT20  
          SMTDCD(IT,M) = SMKPOC(M) * SMTHKC(M)**TT20  
        ENDDO  
        SMTDDP(IT) = SMTHDP**TT20  
        SMTDDD(IT) = SMTHDD**TT20  
        SMTDNH4(IT) = SMTHNH4**TT20  
        SMTDNO3(IT) = SMTHNO3**TT20  
        SMK1H2S(IT)= XSMK1H2S * SMTHH2S**TT20  
        SMTD1CH4(IT) = 0.97656**TT20 * 20.0  
        SMTD2CH4(IT) = SMKCH4 * SMTHCH4**TT20  
        SMTDSI(IT) = SMKSI * SMTHSI**TT20  

        STEMP=STEMP + WQTDsINC
      ENDDO  
      ! *** DSLLC END BLOCK
C  
C17  
C  
      WRITE(2,998)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      READ(1,*) SMPON(1,1),SMPON(1,2),SMPON(1,3),SMPOP(1,1),  
     &    SMPOP(1,2),SMPOP(1,3),SMPOC(1,1),SMPOC(1,2),SMPOC(1,3)  
      IF(ISMICI.NE.1 .AND. ISMICI.NE.2)  
     &    WRITE(2,5105) SMPON(1,1),SMPON(1,2),SMPON(1,3),SMPOP(1,1),  
     &    SMPOP(1,2),SMPOP(1,3),SMPOC(1,1),SMPOC(1,2),SMPOC(1,3)  
C  
C18  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      READ(1,*) SM1NH4(1),SM2NH4(1),SM2NO3(1),SM2PO4(1),SM2H2S(1),  
     &    SMPSI(1),SM2SI(1),SMBST(1),SMT(1)  
      IF(ISMICI.NE.1 .AND. ISMICI.NE.2)THEN  
        WRITE(2,5105) SM1NH4(1),SM2NH4(1),SM2NO3(1),SM2PO4(1),SM2H2S(1),  
     &      SMPSI(1),SM2SI(1),SMBST(1),SMT(1)  
        DO L=2,LA  
          DO M=1,NSMG  
            SMPON(L,M)=SMPON(1,M)  
            SMPOP(L,M)=SMPOP(1,M)  
            SMPOC(L,M)=SMPOC(1,M)  
          ENDDO  
          SM1NH4(L)=SM1NH4(1)  
          SM2NH4(L)=SM2NH4(1)  
          SM2NO3(L)=SM2NO3(1)  
          SM2PO4(L)=SM2PO4(1)  
          SM2H2S(L)=SM2H2S(1)  
          SMPSI(L) =SMPSI(1)  
          SM2SI(L) =SM2SI(1)  
          SMBST(L) =SMBST(1)  
          SMT(L)   =SMT(1)  
        ENDDO  
      ENDIF  
C  
C19   SMDIFT IN M^2/D  
C  
      WRITE(2,998)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      DO I=1,ISMZ  
        READ(1,*) MM,SMHSED(I),SMW2(I),SMDD(I),SMDP(I),SMKNH4(I),  
     &      SMK1NO3(I),SMK2NO3(I),SMDP1PO4(I), SODMULT(I)  
        WRITE(2,56) MM,SMHSED(I),SMW2(I),SMDD(I),SMDP(I),SMKNH4(I),  
     &      SMK1NO3(I),SMK2NO3(I),SMDP1PO4(I), SODMULT(I)  
        SMW2(I) = SMW2(I)*SMCW2        ! *** M/Day 
        SMDTOH(I) = DTWQ/SMHSED(I)  
        SMHODT(I) = SMHSED(I)/DTWQ     ! *** pmc - won't work for variable DT
        SMDP(I) = SMDP(I) / (SMHSED(I)*SMPOCR+ 1.E-18)  
        SMDD(I) = SMDD(I) / (SMHSED(I)+ 1.E-18)  
        SMKNH4(I) = SMKNH4(I)*SMKNH4(I) * SMKMNH4  
        SMK1NO3(I) = SMK1NO3(I)*SMK1NO3(I)  
        SM1DIFT(I) = SMDIFT * SMDTOH(I)/(SMHSED(I)+ 1.E-18)  
        SM2DIFT(I) = 1.0 / (1.0 + SM1DIFT(I))  
        SMW2DTOH(I) = 1.0 + SMW2(I)*SMDTOH(I)  
        SMW2PHODT(I) = SMW2(I) + SMHODT(I)  
        SMDPMIN(I) = XSMDPMIN / (SMHSED(I)+ 1.E-18)  
      ENDDO  
      WRITE(2,998)  
C  
C20  
C  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      IF(ISSKIP .GT. 0) CALL SKIPCOMM(1,CCMRM)  
      READ(1,5100) TITLE(1)  
      WRITE(2,5100) TITLE(1)  
      DO I=1,ISMZ  
        READ(1,*) MM,SMFNR(I,1),SMFNR(I,2),SMFNR(I,3),SMFPR(I,1),  
     &      SMFPR(I,2),SMFPR(I,3),SMFCR(I,1),SMFCR(I,2),SMFCR(I,3)  
        WRITE(2,54) MM,SMFNR(I,1),SMFNR(I,2),SMFNR(I,3),SMFPR(I,1),  
     &      SMFPR(I,2),SMFPR(I,3),SMFCR(I,1),SMFCR(I,2),SMFCR(I,3)  
        SUMNBC=SMFNR(I,1)+SMFNR(I,2)+SMFNR(I,3)  
        SUMNBD=SMFPR(I,1)+SMFPR(I,2)+SMFPR(I,3)  
        SUMNBG=SMFCR(I,1)+SMFCR(I,2)+SMFCR(I,3)  
        IF(SUMNBC.LT.0.9999.OR.SUMNBC.GT.1.0001)  
     &      STOP 'ERROR!! SMFNR(I,1)+SMFNR(I,2)+SMFNR(I,3) SHOULD BE 1'  
        IF(SUMNBD.LT.0.9999.OR.SUMNBD.GT.1.0001)  
     &      STOP 'ERROR!! SMFPR(I,1)+SMFPR(I,2)+SMFPR(I,3) SHOULD BE 1'  
        IF(SUMNBG.LT.0.9999.OR.SUMNBG.GT.1.0001)  
     &      STOP 'ERROR!! SMFCR(I,1)+SMFCR(I,2)+SMFCR(I,3) SHOULD BE 1'  
      ENDDO  
      CLOSE(1)  
 6666 FORMAT(A30)  
  998 FORMAT(80X)  
 5105 FORMAT(10F8.2)  
   54 FORMAT(I8, 10F8.3)  
   56 FORMAT(I8, 3F8.3, E8.1, 6F8.3)  
C  
C READ IN MAPPING INFOR. FOR SPATIALLY-VARYING SED PARAMETERS (UNIT #7).  
C  
      DO L=2,LA  
        ISMZMAP(L)=1  
      ENDDO  
      IF(ISMZ .GT. 1)THEN  
        OPEN(1,FILE='WQSDMAP.INP',STATUS='UNKNOWN')  
        WRITE(2,999)  
        READ(1,90) (TITLE(M), M=1,3)  
        WRITE(2,90) (TITLE(M), M=1,3)  
C  
C       READ(1,999)  
C  
        READ(1,999)  
        WRITE(2,999)  
        WRITE(2,92)  
        IN=0  
        IJC=IC*JC  
        DO M=1,IJC  
          READ(1,*,END=1111) I,J,ISMZX  
          IN=IN+1  
          IF(IJCT(I,J).LT.1 .OR. IJCT(I,J).GT.8.OR.ISMZX.GT.ISMZ)THEN  ! *** PMC
            PRINT*, 'I, J, IJCT(I,J) = ', I,J,IJCT(I,J)  
            STOP 'ERROR!! INVALID (I,J) IN FILE WQSDMAP.INP'  
          ENDIF  
          L = LIJ(I,J)  
          ISMZMAP(L)=ISMZX  
          WRITE(2,91) L,I,J,ISMZMAP(L)  
        ENDDO  
 1111   CONTINUE  
        IF(IN.NE.(LA-1))THEN  
          PRINT*, 'ALL ACTIVE SED. CELLS SHOULD BE MAPPED FOR SED PAR.'  
          STOP 'ERROR!! NUMBER OF LINES IN FILE WQSDMAP.INP =\ (LA-1)'  
        ENDIF  
        CLOSE(1)  
      ENDIF  
      CLOSE(2)  
   90 FORMAT(A79)  
   91 FORMAT(15I5)  
   92 FORMAT('    L    I    J    ISMZMAP')  
      RETURN  
      END  
